package nineteen;

/**
 * 更简洁的枚举管理方法，将一个enum嵌套在另一个enum内
 *
 * @author sun.ye
 * @since 2020-05-02 22:43
 */
public enum SecurityCategory {
    /**
     *  存货、关系
     */
    STOCK(Security.Stock.class),BOND(Security.Bond.class);
    Security[] values;

    SecurityCategory(Class<? extends Security> kind) {
        values = kind.getEnumConstants();
    }

    interface Security{
        enum Stock implements Security{
            /**
             * 长,短,边缘
             */
            SHORT,LONG,MARGIN
        }
        enum Bond implements Security{
            /**
             * 市政、垃圾
             */
            MUNICIPAL,JUNK
        }
    }

    public Security randomSelection(){
        return Enums.random(values);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10 ; i++) {
            SecurityCategory category = Enums.random(SecurityCategory.class);
            System.out.println(category + ": " + category.randomSelection());
        }
    }
}


